
function RollString(){
        /*随机生成id*/
        var ele = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    
        function rollChar(ele){
                var randomInt = Math.round(Math.random() * ele.length - 1);
                return ele.charAt(randomInt);
        }

        this.roll = function(len){
                var re = new Date().getTime().toString();
                for(var x = 0;x < len;x++){
                        re = re + rollChar(ele);
                }
                return re;
        }
}

function Loop(array){
        /*对输入的数组，进行循环输出*/
        var color = array;
        var index = -1;
        var max = color.length - 1;
            
        this.loop = function(){
                index++;
                if(index > max){
                        index = 0;
                }
                return color[index];
        }
}

function formatDate(date){
        /*输出格式化后的日期1988-08-08 17:18:30*/
        var year = date.getFullYear();
        var mon = date.getMonth() + 1;
        var day = date.getDate();
                
        var hour = date.getHours();
        var min = date.getMinutes();
        var sec = date.getSeconds();
        return year + "-" + mon + "-" + day + " " + hour + ":" + min + ":" + sec;
}

function setMid(target,speed,type){
        /*对于设置为居中*/
        var sw = document.documentElement.clientWidth;
        var sh = document.documentElement.clientHeight;
        $(target).css("position" , "absolute");
        var w = d(target).width;
        var h = d(target).height;
    
        switch(type){
                case "xy" : {
                        $(target).stop(true,false).animate({
                                top : (sh - h) / 2,
                                left : (sw - w) / 2
                        }, speed);
                        break;
                }
                case "x" : {
                        $(target).stop(true,false).animate({
                                left : (sw - w) / 2
                        }, speed);  
                        break;
                }
                case "y" : {
                        $(target).stop(true,false).animate({
                                top : (sh - h) / 2
                        }, speed);    
                        break;
                }
        }
}

function d(jquery){
        /*通过jquery，获取对象的位置大小信息*/
        return{
                top : $(jquery).offset().top,
                left : $(jquery).offset().left,
                right : $(jquery).offset().right,
                width : parseInt($(jquery).css("width")),
                height : parseInt($(jquery).css("height"))
        }
}

function createRelativePath(level){
        var prefix = "../";
        var re = "";
        for(var x = 0;x < level;x++){
                re = re + prefix;
        }
        return re;
}

function sleek(obj,speed){
        /*滑动到指定的对象*/
        $("html,body").animate({
                scrollTop : d(obj).top
        }, speed);
}

function tableGetSelected(table){
        /*datatable的专用方法，寻找被选中对行*/
        var aTrs = table.fnGetNodes();	
        for (var i=0 ; i<aTrs.length ; i++){
                if ($(aTrs[i]).hasClass("row_selected")){
                        return aTrs[i];
                }			
        }	
        return null;
}
                        
function getForm(string){
        var re = {}
        var objs = $("*[" + string + "]");
        $.each(objs,function(k,v){
                re[$(v).attr(string)] = $(v).val();
        });
        return re;
}

function setForm(string,res){
        $.each(res,function(k,v){
                $("*[" + string + "=" + k + "]").val(v);
        });
}
